package com.it.bannner.api

import com.haiheng.voiceandbook.Constants.Companion.BASE_URL
import com.haiheng.voiceandbook.common.BaseDto
import com.haiheng.voiceandbook.common.DeviceInfoDto
import com.it.bannner.interceptor.HeadInterceptor
import com.it.bannner.log.LogWriter
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
import okhttp3.OkHttpClient
import okhttp3.ResponseBody
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query
import retrofit2.http.Streaming
import java.util.concurrent.TimeUnit


//ACS平台
interface ApiService {
    companion object Factory {





        val apiService = create()

        fun create(): ApiService {

            val okHttpClient = OkHttpClient.Builder()
                .addInterceptor(HttpLoggingInterceptor({ message -> //访问网络请求，和服务端响应请求时。将数据拦截并输出
                    LogWriter.e("Http: $message")
                }).setLevel(HttpLoggingInterceptor.Level.BODY)) //Log等级
                .addInterceptor(HeadInterceptor())
                .connectTimeout(16, TimeUnit.SECONDS).build()
            val retrofit = Retrofit.Builder()
                .client(okHttpClient)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(CoroutineCallAdapterFactory())
                .baseUrl(BASE_URL)
                .build()
            return retrofit.create(ApiService::class.java)
        }
    }

    /**
     * 获取视频
     */
    @GET("/sb/getVideo")
    suspend fun getVideo(@Query("type") type: Int,@Query("code") code: String): BaseDto<MutableList<String>>


    /**
     * 下载视频
     */
    @GET("{path}")
    @Streaming
    suspend fun downLoadVideo(@Path("path") path: String): ResponseBody

    /**
     * 获取设备信息
     */
    @GET("/sb/getDeviceInfo")
    suspend fun getDeviceInfo(@Query("code") code: String,@Query("type") type: Int): BaseDto<DeviceInfoDto>


}